package com.bai.easyui.DaoImp;

import com.bai.easyui.Dao.UserDao;
import com.bai.easyui.bean.CriteriaUser;
import com.bai.easyui.bean.User;

import java.util.List;

/**
 * Created by Admin on 2/10 0010.
 */
public class UserDaoImp extends BaseDaoImp<User> implements UserDao {
    @Override
    public void save(User user) {
        String sql="insert into user (name,password,sex,age,birthday,city,salary,startTime,endTime,description) " +
                "values (?,?,?,?,?,?,?,?,?,?)";
        update(sql,user.getName(),user.getPassword(),user.getSex(),user.getAge(),user.getBirthday(),user.getCity(),
                user.getSalary(),user.getStartTime(),user.getEndTime(),user.getDescription());
    }

    @Override
    public List<User> getAll() {
        String sql="select * from user";
        return getList(sql);
    }

    @Override
    public List<User> getPagination(Integer page, Integer pageSize,CriteriaUser cu) {
      //  String sql="select * from user limit ?,?";
        String sql="select * from user where name like ? and startTime like ? and endTime like ?  limit ?,?";
        return getList(sql,cu.getName(),cu.getStartTime(),cu.getEndTime(),(page-1)*pageSize,pageSize);
    }

    @Override
    public long getTotal(CriteriaUser cu) {
        String sql="select count(id) from user where name like ? and startTime like ? and endTime like ? order by ?";
        return getForValue(sql,cu.getName(),cu.getStartTime(),cu.getEndTime());
    }

    @Override
    public User findById(int id) {
        String sql="select * from user where id=?";
        return get(sql,id);
    }

    @Override
    public void edit(User user) {
        String sql="update user set name=?,password=?,sex=?," +
                "age=?,birthday=?,city=?,salary=?,startTime=?,endTime=?,description=? where id=?";
        update(sql,user.getName(),user.getPassword(),user.getSex(),user.getAge(),user.getBirthday(),user.getCity(),
                user.getSalary(),user.getStartTime(),user.getEndTime(),user.getDescription(),user.getId());
    }

    @Override
    public void delete(int i) {
        String sql="delete from user where id=?";
        update(sql,i);
    }

//    @Override
//    public List<User> getForListWithCriteriaUser(CriteriaUser cu) {
//        String sql="select * from user where name like ? and startTime like ? and endTime like ?";
//        return getList(sql,cu.getName(),cu.getStartTime(),cu.getEndTime());
//    }


}
